/*package com.qc.common;

import javax.servlet.http.HttpServletResponse;

public class UserCookie {

    public String getIpAddr(HttpServletRequest request) {
        String ip = request.getHeader("X-Real-IP");
        if (!StringUtils.isEmpty(ip) && !"unknown".equalsIgnoreCase(ip)) {
                return ip;
        }
        ip = request.getHeader("X-Forwarded-For");
        if (!StringUtils.isEmpty(ip) && !"unknown".equalsIgnoreCase(ip)) {
            // 多次反向代理后会有多个IP值，第一个为真实IP。
            int index = ip.indexOf(',');
            if (index != -1) {
                   return ip.substring(0, index);
            } else {
                   return ip;
            }
        } else {
               return request.getRemoteAddr();
        }
    }
    
    public void setcookie(HttpServletResponse response){
        
        Cookie cookie = new Cookie("cookiename","cookievalue");
        response.addCookie(cookie);
        //下面建立一个有生命周期的cookie,可以设置他的生命周期
    
    
        cookie = new Cookie("cookiename","cookievalue");
         
        cookie.setMaxAge(3600);
         
        //设置路径，这个路径即该工程下都可以访问该cookie 如果不设置路径，那么只有设置该cookie路径及其子路径可以访问
        
        cookie.setPath("/");
        response.addCookie(cookie);
         
        //下面介绍如何读取cookie，读取cookie代码如下
        Cookie[] cookies = request.getCookies();//这样便可以获取一个cookie数组
        for(Cookie cookie2 : cookies){
            cookie2.getName();// get the cookie name
            cookie2.getValue(); // get the cookie value
        }
         
    
        //上面就是基本的读写cookie的操作。
        //我们在实际中最好进行一下封装，比如增加一个cookie，我们关注的是cookie的name，value,生命周期，所以进行封装一个函数，
        //当然还要传入一个response对象，addCookie()代码如下

    }
    *//**
     * 设置cookie
     * @param response
     * @param name  cookie名字
     * @param value cookie值
     * @param maxAge cookie生命周期  以秒为单位
     *//*
    
    public  void addCookie(HttpServletResponse response,String name,String value){
        //例如：
            //name为：IP(192.168.1.201) 值为：username,password
        Cookie cookie = new Cookie(name,value);
        cookie.setPath("/");
        cookie.setMaxAge(365*24*60*60);
        //5*365*24*60*60  5年
       // if(maxAge>0)  cookie.setMaxAge(maxAge);
        response.addCookie(cookie);
    }
     
    *//**
     * 根据名字获取cookie
     * @param request
     * @param name cookie名字
     * @return
     *//*
    public Cookie getCookieByName(HttpServletRequest request,String name){
        Map<String,Cookie> cookieMap = ReadCookieMap(request);
        if(cookieMap.containsKey(name)){
            Cookie cookie = (Cookie)cookieMap.get(name);
            return cookie;
        }else{
            return null;
        }   
    }
     
    *//**
     * 将cookie封装到Map里面
     * @param request
     * @return
     *//*
    private static Map<String,Cookie> ReadCookieMap(HttpServletRequest request){  
        Map<String,Cookie> cookieMap = new HashMap<String,Cookie>();
        Cookie[] cookies = request.getCookies();
        if(null!=cookies){
            for(Cookie cookie : cookies){
                cookieMap.put(cookie.getName(), cookie);
            }
        }
        return cookieMap;
    }
    
    *//**
     * 保存用户登录cookie
     * 
     *//*
    public  void addUserInfoCookie(HttpServletResponse response, UserInfo userInfo){
        String name = SystemEnums.Project.ARCHIST_FRONT_WEB.getCode() + "_USER_ID";
        String id = userInfo.getId();
        String userName = userInfo.getLoginName();
        String password = userInfo.getPassword();
        String lastLoginTime = String.valueOf(userInfo.getLastLoginTime().getTime());
        UserCookieQo userCookieQo = new UserCookieQo();
        userCookieQo.setId(id);
        userCookieQo.setUserName(userName);
        userCookieQo.setPassword(password);
        userCookieQo.setLastLoginTime(lastLoginTime);
        String value = JsonUtils.toJson(userCookieQo);
        Cookie cookie = new Cookie(name, value);
        cookie.setPath("/");
        cookie.setMaxAge(365*24*60*60);
        response.addCookie(cookie);
    }
    
    *//**
     * 获取用户登录cookie
     * 
     *//*
    public UserCookieQo getUserInfoCookie(HttpServletRequest request){
        UserCookieQo userCookieQo = null;
        String name = SystemEnums.Project.ARCHIST_FRONT_WEB.getCode() + "_USER_ID";
        Map<String,Cookie> cookieMap = ReadCookieMap(request);
        if (cookieMap.containsKey(name)) {
            Cookie cookie = (Cookie)cookieMap.get(name);
            userCookieQo = (UserCookieQo)JsonUtils.fromJson(cookie.getValue(), UserCookieQo.class);
        }
        return userCookieQo;
    }
    
    *//**
     * 清除用户登录cookie
     * 
     *//*
    public void cleanUserInfoCookie(HttpServletResponse response){
        String name = SystemEnums.Project.ARCHIST_FRONT_WEB.getCode() + "_USER_ID";
        Cookie cookie = new Cookie(name, null);
        cookie.setPath("/");
        cookie.setMaxAge(0);
        response.addCookie(cookie);
    }
}
*/